/*
 * This file (RxGradient.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package alkwarel.filters;

import java.awt.Color;

import processing.core.PImage;
import alkwarel.objects.AkArtspace;
import alkwarel.objects.RxFilter;

/**
 * @author Xavier Gouchet
 *
 */
public class RxGradient extends RxFilter {

	/**
	 * Standard Constructor
	 */
	public RxGradient() {
		super(2005, "gradient");
	}

	/**
	 * @see alkwarel.objects.RxFilter#Apply(alkwarel.objects.AkArtspace)
	 */
	public boolean Apply(AkArtspace a) {
		PImage imgx = a.get();
		for (int x=0; x<a.width; x++){
			for (int y=0; y<a.height; y++){
				if ((x>0)&&(y>0)){
					float redout =   (255 - Math.min(255, 2*Math.abs(red(imgx.get(x,y))   -   red(imgx.get(x-1, y)))   + Math.abs(red(imgx.get(x,y))   - red(imgx.get(x,y-1))))) ;
					float greenout = (255 - Math.min(255, 2*Math.abs(green(imgx.get(x,y)) - green(imgx.get(x-1, y))) + Math.abs(green(imgx.get(x,y)) - green(imgx.get(x,y-1))))) ;
					float blueout =  (255 - Math.min(255, 2*Math.abs(blue(imgx.get(x,y))  -  blue(imgx.get(x-1, y)))  + Math.abs(blue(imgx.get(x,y))  - blue(imgx.get(x,y-1))))) ;   
					coulref = new Color((int)redout, (int)greenout, (int)blueout).getRGB();
					a.set(x, y , coulref);
		        }
			}		
		}
		return true;
	}

}
